<body>
<script src="full-screen-test.js"></script>
<span></span>
<script>
    var callback;
    var fullscreenChanged = function(event)
    {
        if (callback)
            callback(event)
    };
    waitForEvent(document, 'webkitfullscreenchange', fullscreenChanged);

    var span = document.getElementsByTagName('span')[0];

    var spanEnteredFullScreen = function() {
        testExpected("document.webkitIsFullScreen", true);
        testExpected("document.webkitCurrentFullScreenElement", span);
        callback = cancelledFullScreen;
        document.webkitCancelFullScreen();
    };

    var cancelledFullScreen = function() {
        testExpected("document.webkitIsFullScreen", false);
        testExpected("document.webkitCurrentFullScreenElement", undefined);
        callback = failFullScreenTest;
        document.webkitCancelFullScreen();
        setTimeout(endTest, 0);
    };

    var failFullScreenTest = function() {
        consoleWrite("Should not have received a webkitfullscreenchange event.");
        endTest();
    };

    callback = spanEnteredFullScreen;
    runWithKeyDown(function(){span.webkitRequestFullScreen()});
</script>
